<?php

class DB_Shard_Table extends DB_Shard {

	/**
	 * 此分库规则下的数据库配置信息
	 *
	 */
	private $_db = array();

	/**
	 * 分库的关键字
	 * 此变量暂时不用
	 * @var array
	 */
	private $_shardKey;

	/**
	 * 传入的数据库配置信息
	 *
	 * @var array
	 */
	private $_options;

	public function __construct($options, $shardKey = array()) {

		$this->_options = $options;

		// 此变量暂时未用到
		$this->_shardKey = $shardKey;

		$this->shard($options['config'], $shardKey);
	}

	/**
	 * shard
	 * 分片处理，获取传入的数据库配置
	 *
	 * @param array $shards
	 * @param array $shardKey
	 * @return boolean
	 * @throws Exception
	 */
	protected function shard($shards, $shardKey = array()) {

		try {
			$this->_db['dsn'] = $shards['dsn'];
			$this->_db['user'] = $shards['user'];
			$this->_db['password'] = $shards['password'];
			$this->_db['charset'] = $shards['charset'];
			$this->_db['persistent'] = $shards['persistent'];

		} catch (Exception $e) {
			throw new Exception($e);
		}

		return true;
	}

	/**
	 * getDB
	 * 获取数据库配置
	 *
	 * @return array
	 */
	public function getDB() {

		return $this->_db;
	}
}
